package flextv.main.command {

import com.adobe.cairngorm.commands.ICommand;
import com.adobe.cairngorm.control.CairngormEvent;

import flextv.core.event.PopupCloseEvent;
import flextv.core.logic.Logger;
import flextv.main.event.ImportEvent;
import flextv.main.logic.WatchIdImporter;
import flextv.main.view.ImportPopup;

import mx.logging.ILogger;

public class ImportCommand implements ICommand {
	
	private static const LOG: ILogger = Logger.getLog(ImportCommand);
	
	public function ImportCommand() {
	}

	public function execute(_event: CairngormEvent): void {
		const event: ImportEvent = _event as ImportEvent;
		LOG.info("Executing [event=" + event + "].");
		
		
		const popup: ImportPopup = new ImportPopup();
		popup.addEventListener(PopupCloseEvent.POPUP_CLOSE, function (closeEvent: PopupCloseEvent): void {
			if(popup.isConfirmed) {
				LOG.info("Confirmed popup close with id [" + popup.watchId + "]");
				new WatchIdImporter(popup.watchId, event.targetPlaylist).doImport();
				
			} else {
				LOG.debug("Closing import popup without confirmation.");
			}
		}); 
		popup.display();
		
		
		
		/*
		const importer: WatchIdImporter = new WatchIdImporter(watchId, new ResponderAdapter(
			function(result: Object): void {
 				// ... result handling ...
 				trace("import command; result");
 			},
 			function(faultInfo: Object): void {
 				// ... error handling ...
 				trace("import command; error");
 			}
		));
		importer.doImport();
		*/
	}
		
}
}